package com.beinhospital_sw21_h2_05.beinhospitalsw21h205.controller;

import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Clerk;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Department;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Linshi3;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Medicine;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.service.ClerkService;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.PageBean;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 控制器类，处理与收费员（Clerk）相关的HTTP请求
 */
@CrossOrigin
@Slf4j
@RestController
public class ClerkController {

    @Autowired
    private ClerkService clerkService;

    /**
     * 收费员分页查询
     * @param page 页码，默认为1
     * @param pageSize 每页大小，默认为10
     * @param clerkName 收费员姓名，可选
     * @return 分页查询结果
     */
    @GetMapping("/clerk")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String clerkName) {
        log.info("收费员分页查询：{}，{},{}", page, pageSize, clerkName);
        PageBean pageBean = clerkService.page(page, pageSize, clerkName);
        return Result.success(pageBean);
    }

    /**
     * 根据收费员ID删除收费员
     * @param clerkID 收费员ID
     * @return 操作结果
     */
    @DeleteMapping("/clerk/{clerkID}")
    public Result delete(@PathVariable Integer clerkID) {
        log.info("根据id删除收费员：{}", clerkID);
        clerkService.delete(clerkID);
        return Result.success();
    }

    /**
     * 新增收费员
     * @param linshi3 包含新增收费员信息的对象
     * @return 操作结果
     */
    @PostMapping("/clerk")
    public Result insert(@RequestBody Linshi3 linshi3) {
        log.info("新增收费员：{}", linshi3);
        clerkService.add(linshi3);
        return Result.success();
    }

    /**
     * 编辑收费员信息
     * @param linshi3 包含编辑后的收费员信息的对象
     * @return 操作结果
     */
    @PutMapping("/clerk")
    public Result update(@RequestBody Linshi3 linshi3) {
        log.info("编辑收费员：{}", linshi3);
        clerkService.update(linshi3);
        return Result.success();
    }
}
